import { BasicColumn } from '@/components/Table';
import { FormSchema } from '@/components/Table';

export const columns: BasicColumn[] = [
  {
    title: '表头名称',
    align: 'center',
    dataIndex: 'secdName',
  },
  {
    title: '字段名称',
    align: 'center',
    dataIndex: 'secdFieldName',
  },
  {
    title: '宽度',
    align: 'center',
    dataIndex: 'secdWidth',
  },
  {
    title: '高度',
    align: 'center',
    dataIndex: 'secdHeight',
  },
  {
    title: '字段类型',
    align: 'center',
    dataIndex: 'secdType',
  },
  {
    title: '日期/时间格式化',
    align: 'center',
    dataIndex: 'secdFormat',
  },
  {
    title: '格式化',
    align: 'center',
    dataIndex: 'secdNumFormat',
  },
  {
    title: '顺序',
    align: 'center',
    dataIndex: 'secdOrder',
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
  // {
  //   field: 'secdPid',
  //   label: '上级id 兼容嵌套的极端情况',
  //   component: 'Input',
  //   // required: true,
  // },
  {
    field: 'secId',
    label: '配置主表id',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'secdFieldName',
    label: '字段名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'secdName',
    label: '表头名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'secdType',
    label: '字段类型',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        options: [
          {
            label: '字符串/日期/时间',
            value: 1,
          },
          {
            label: '数字',
            value: 10,
          },
        ],
        onChange: (v) => {
          if (v === 10) formModel.secdNumFormat = '#.##';
          if (v === 1) {
            formModel.secdTimeZoon = '';
            formModel.secdFormat = '';
          }
        },
      };
    },
  },
  {
    field: 'secdTimeZoon',
    label: '时区',
    component: 'Input',
    defaultValue: 'GMT+8',
    ifShow: ({ values }) => values.secdType === 1,
  },
  {
    field: 'secdFormat',
    label: '格式化',
    component: 'ApiSelect',
    ifShow: ({ values }) => values.secdType === 1,
    componentProps: {
      dictCode: 'export_date_field_type',
    },
  },
  {
    field: 'secdNumFormat',
    label: '格式化',
    component: 'Input',
    helpMessage: '#.##',
    required: true,
    ifShow: ({ values }) => values.secdType === 10,
  },
  {
    field: 'secdWidth',
    label: '宽度',
    component: 'InputNumber',
    defaultValue: 10,
    required: true,
  },
  {
    field: 'secdHeight',
    label: '高度',
    defaultValue: 10,
    component: 'InputNumber',
    required: true,
  },
  {
    field: 'secdOrder',
    label: '顺序',
    component: 'InputNumber',
    required: true,
  },
];
